<?php
	class MainController extends CController{
		private $result = array("actionStatus"=>0,"actionMessage"=>"","model"=>array(),"actionError"=>array());	
		public $mainMenu = "Finance";
		public $subMenu = "";
		public $title = "";
		
		public function init() {
						
		}
		
		public function actionIndex(){
			$this->layout ="//layouts/ly_blank";
			$this->render('index');
		}
				
		public function actionTahunAjaran(){		
			$this->subMenu = "Tahun Ajaran";
			$this->layout ="//layouts/ly_blank";
			$this->render('tahunAjaran');
		}
		
		public function actionTahunAjaranDetailList(){		
			$conn = Yii::app()->db;
			$onlyActive = Yii::app()->request->getParam("activeOnly",false);			
			try{
				if ($onlyActive){
					$sql ="select * from m_tahun_ajaran where is_active = true";
				}else{
					$sql ="select * from m_tahun_ajaran";
				}
				$command = $conn->createCommand($sql);
				//$command->bindParam(":id",$id,PDO::PARAM_INT);
				//or $rs =$command->query(array(':id'=>$id));				
				//$rs =$command->query(array(':id'=>$id));
				$rs =$command->query();
				$rw = $rs->readAll();
				$this->result["actionStatus"] =0;
				$this->result["actionMessage"] ="";
				$this->result["actionError"] =array();
				$this->result["model"] = $rw;
			}catch(Exception $e){
				$this->result["actionStatus"] =2;
				$this->result["actionMessage"] =$e->getMessage();
			}			
			header('Content-type:application/json');
			echo CJSON::encode($this->result);
		}
		
		
		protected function beforeRender($view){
			if ($this->subMenu != ""){
				$this->title = $this->mainMenu . " - " .$this->subMenu;
			}
			return true;
		}
		
	}
?>